/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.rainbow.xml;

import java.io.File;
import java.io.IOException;
import java.util.List;
import org.rainbow.file.FileReader;
import org.rainbow.udo.UConnection;
import org.rainbow.udo.UdoHandleException;
import org.rainbow.udo.UQuery;

/**
 *
 * @author hironaga
 */
public class XmlReader extends FileReader{

    private static XmlNativeHandler nativeHandler = new XmlNativeHandlerImpl();

    public <T> T read(UConnection uconn, UQuery uquery, Class<T> clazz)
                                                   throws UdoHandleException{

        File file = uconn.getFile();
        String xpath = uquery.getXpath().getXpath();
        try {
            return  nativeHandler.readObject(file, xpath, clazz);
        } catch (IOException ex) {
            throw new UdoHandleException(ex);
        }
    }

    public <T> List<T> readList(UConnection uconn, UQuery uquery, Class<T> clazz)
                                                    throws UdoHandleException {

        File file = uconn.getFile();
        String xpath = uquery.getXpath().getXpath();
        try {
            return nativeHandler.readList(file, xpath, clazz);
        } catch (IOException ex) {
            throw new UdoHandleException(ex);
        }
    }

}
